package com.superman.supermarket.client.composite.home.entry;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.mvpframe.client.widget.lazy.LazyImage;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.event.PageJumpEvent;

/**
 * 首页入口模块-子元素
 * 
 * @author superman
 * @version 2018年7月20日下午8:44:02
 */
public class HomeEntryModule extends Composite implements IUIModule {

	interface HomeEntryModuleUiBinder extends UiBinder<Widget, HomeEntryModule> {
	}

	private static HomeEntryModuleUiBinder uiBinder = GWT.create(HomeEntryModuleUiBinder.class);

	@UiField
	LazyImage image;
	private String jumpUrl;
	@UiField
	FlowPanel mainpanel;

	@UiField
	HTML namehtml;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年7月20日 下午8:44:04
	 */
	public HomeEntryModule() {
		initWidget(uiBinder.createAndBindUi(this));

		mainpanel.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// Window.Location.assign(jumpUrl);

				XGinjector.INSTANCE.getEventBus().fireEvent(new PageJumpEvent(jumpUrl));
			}
		}, ClickEvent.getType());
	}

	@Override
	public Map<String, Object> getData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setData(Map<String, Object> map) {
		this.jumpUrl = String.valueOf(map.get("PIC_GOTO"));
		image.setUrl(String.valueOf(map.get("PIC_URL")));
		namehtml.setText(String.valueOf(map.get("NAME")));
	}

}
